package com.zjcode.cdcer.controller;

import com.alibaba.fastjson.JSONObject;
import com.chinatechstar.component.commons.controller.BaseController;
import com.chinatechstar.component.commons.result.ListResult;
import com.chinatechstar.component.commons.supports.PageData;
import com.zjcode.cdcer.model.ZjcodeSysUserTmp;
import com.zjcode.cdcer.model.basic.JsonObj;
import com.zjcode.cdcer.service.CerCasUsersyncinfoService;
import javax.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName:CerCasUsersyncinfoController
 * @功能：
 * @author：wlei
 * @日期：2023/2/7-01:07
 **/
@RestController
@Slf4j
@RequestMapping("/v1/casusersync/")
public class CerCasUsersyncinfoController extends BaseController {

    @Autowired
    private CerCasUsersyncinfoService cerCasUsersyncinfoService;

    @GetMapping("listByPage")
    public ListResult<Object> listByPage(HttpServletResponse response) {
        return cerCasUsersyncinfoService.listByPage(getPageData());
    }

    @GetMapping("queryAllUnInitSysuserCount")
    public JsonObj queryAllUnInitSysuserCount(HttpServletResponse response) {
        return cerCasUsersyncinfoService.queryAllUnInitSysuserCount(getPageData());
    }

    @GetMapping("findUserById")
    public JsonObj findUserById() {
        PageData pageData = getPageData();
        return cerCasUsersyncinfoService.findUserById(pageData);
    }

    @PostMapping("addSysUser")
    public JsonObj addSysUser(@RequestBody ZjcodeSysUserTmp record) {
        PageData pageData = getPageData();
        pageData.put("data", JSONObject.toJSONString(record));
        return cerCasUsersyncinfoService.addSysUser(pageData);
    }

    @PostMapping("syncTmpUserToSysUser")
    public JsonObj syncTmpUserToSysUser(@RequestBody ZjcodeSysUserTmp record) {
        PageData pageData = getPageData();
        pageData.put("data", JSONObject.toJSONString(record));
        return cerCasUsersyncinfoService.syncTmpUserToSysUser(pageData);
    }

    @PostMapping("updateSysUser")
    public JsonObj updateSysUser(@RequestBody ZjcodeSysUserTmp record) {
        PageData pageData = getPageData();
        pageData.put("data", JSONObject.toJSONString(record));
        return cerCasUsersyncinfoService.updateSysUser(pageData);
    }
}
